<template>
<div class="">
  <div class="crumbs">
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{path: '/home'}"><i class="el-icon-setting"></i> 首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{path: '/menu'}">导航</el-breadcrumb-item>
      <el-breadcrumb-item>编辑</el-breadcrumb-item>
    </el-breadcrumb>
  </div>
  <el-tabs>
    <el-tab-pane label="基本资料">
      <div class="form-box">
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="名称">
            <el-input v-model="form.m_name"></el-input>
          </el-form-item>
          <el-form-item label="链接">
            <el-input v-model="form.m_path"></el-input>
          </el-form-item>
          <el-form-item label="显示">
            <el-switch on-text="ON" off-text="OFF" on-value="1" off-value="0" v-model="form.m_is_open"></el-switch>
          </el-form-item>
          <el-form-item label="排序">
            <el-input-number v-model="form.m_sort"></el-input-number>
          </el-form-item>
          <el-form-item label="web title">
            <el-input type="textarea" v-model="form.m_web_title"></el-input>
          </el-form-item>
          <el-form-item label="web keyword">
            <el-input type="textarea" v-model="form.m_web_keyword"></el-input>
          </el-form-item>
          <el-form-item label="web description">
            <el-input type="textarea" v-model="form.m_web_description"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">提交</el-button>
            <el-button>取消</el-button>
          </el-form-item>
        </el-form>

      </div>

    </el-tab-pane>
  </el-tabs>
</div>
</template>

<script>
import Objres from '@/components/common/ObjResult';
let token = localStorage.getItem('admin-token');

export default {
    data () {
        return {
            form: {
                // h_id: 0,
                m_name: '',
                m_path: '',
                m_parent: 0,
                m_web_title: '',
                m_web_keyword: '',
                m_web_description: '',
                m_sort: 0,
                m_is_open: 0
            },
            webUrl: this.WEB_CONFIG.weburl
            // uploadName: ''
        };
    },
    methods: {
        onSubmit () {
            let self = this;
            console.log('submit!');
            this.$http.post(
                self.webUrl + '/admin/menu/save?token=' + token,
                // {'DB_House': self.form},
                // {'DB_House': {'h_name': '9527'}},
                self.form,
                {'emulateJSON': true}
                // {headers: {'Content-Type': 'multipart/form-data'}}
            ).then((response) => {
                let res = response.body;
                console.log(res);
                if (res.status === Objres.ObjResult.RESULT_OK) {
                    this.$message({message: '保存成功!', type: 'success'});
                    self.$router.push('/menu/' + res.data.m_id);
                } else {
                    this.$message({message: '保存失败!', type: 'error'});
                }
            });
        },
        getData (id) {
            let self = this;
            // let token = localStorage.getItem('admin-token');
            console.log(token);
            if (token) {
                this.$http.post(
                    self.webUrl + '/admin/menu/show?token=' + token + '&id=' + id,
                    self.postData,
                    {'emulateJSON': true}
                    // {headers: {'Content-Type': 'multipart/form-data'}}
                ).then((response) => {
                    let res = response.body;
                    // console.log(res);
                    if (res.status === Objres.ObjResult.RESULT_OK) {
                        self.form = res.data;
                    }
                });
            } else {
                this.$message({message: '请登陆', type: 'error'});
                self.$router.push('/login');
            }
        }
    },
    created () {
        if (this.$route.params.id) {
            console.log(this.$route.params.id);
            this.getData(this.$route.params.id);
        }
    }

};
</script>

<style lang="css">
</style>
